import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CountDownLatch;

public class Producer implements Runnable {
	private final BlockingDeque<Integer>[] dequeues;
	CountDownLatch latch;

	public Producer(BlockingDeque<Integer>[] dequeues, CountDownLatch latch) {
		this.dequeues = dequeues;
		this.latch = latch;
	}

	public void run() {
		try {
			for (int i = 1; i <= 256; i++) {
				int index = (int) (Math.random() * dequeues.length);
				dequeues[index].put(i * 512 - 1);
			}
			System.out.println(Thread.currentThread().getName()
					+ " finished submitting tasks.");
			latch.countDown();

		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}
	}
}